<?php /** @noinspection PhpMissingParamTypeInspection */

/** @noinspection PhpMissingFieldTypeInspection */

namespace Dreamcat\Class2Array\DemoClass;

use JsonSerializable;

/**
 * 一个实现了 JsonSerializable 的测试类
 * @author vijay
 */
class Jsonabled implements JsonSerializable
{
    /** @var mixed */
    private $count;

    /**
     * Jsonabled constructor.
     * @param mixed $count 赋值给$count
     */
    public function __construct($count = null)
    {
        $this->count = $count;
    }

    /**
     * 获取可json化数据
     * @return array|null 可json化的数据
     */
    public function jsonSerialize(): ?array
    {
        if ($this->count === null) {
            return null;
        } else {
            return ["count" => $this->count];
        }
    }
}

# end of file
